//
//  APIManager.m
//  InsuranceMarketing
//
//  Created by initial on 2018/1/26.
//  Copyright © 2018年 initial. All rights reserved.
//

#import "APIBase.h"
#import "APIManager.h"
#import "AFNetworking.h"
#import "AFNetworkActivityIndicatorManager.h"


//#define DateTIME   [NSString stringWithFormat:@"%ld",(long)([[NSDate date]timeIntervalSince1970])]

//#define DateTIME   [NSString stringWithFormat:@"%.0f",([[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970]*1000)]
//#define CUSTOM [NSString stringWithFormat:@"http://iir.circ.gov.cn/web/servlet/ValidateCode?time=%@",DateTIME]


//#define DateTIME   @"123"



#define CUSTOM [NSString stringWithFormat:@"http://iir.circ.gov.cn/web/servlet/ValidateCode?time=%@",DateTIME]


@implementation APIManager

+ (instancetype)sharedNetManager
{
    static id sharedNetManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedNetManager = [[super allocWithZone:NULL] init];
    });
    return sharedNetManager;
}

#pragma mark - 网络状态监测
/*!
 *  开启网络监测
 */
+ (void)startNetWorkMonitoringWithBlock:(NetworkStatusBlock)networkStatus
{
    /*! 1.获得网络监控的管理者 */
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    /*! 当使用AF发送网络请求时,只要有网络操作,那么在状态栏(电池条)wifi符号旁边显示  菊花提示 */
    [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
    /*! 2.设置网络状态改变后的处理 */
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        /*! 当网络状态改变了, 就会调用这个block */
        switch (status)
        {
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                networkStatus ? networkStatus(NetworkStatusUnknown) : nil;
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"没有网络");
                networkStatus ? networkStatus(NetworkStatusNotReachable) : nil;
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"手机自带网络");
                networkStatus ? networkStatus(NetworkStatusReachableViaWWAN) : nil;
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"wifi 网络");
                networkStatus ? networkStatus(NetworkStatusReachableViaWiFi) : nil;
                break;
        }
    }];
    [manager startMonitoring];
}









@end
